﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using KVB.Common;
using Customer_Profile.eCard.DBDao;
using Customer_Profile.Admin;

namespace Customer_Profile.eCard
{
    public partial class ProdList : System.Web.UI.Page
    {
        string strUserName = "";
        string strUserID = "";
        string strEntity = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            Comm.CheckSession(this.Page, "/login.aspx", "usermodel");
            if (Session["usermodel"] != null)
            {
                strUserID = ((UserInfoEntity)Session["usermodel"]).UserLoginId;
                strUserName = ((UserInfoEntity)Session["usermodel"]).UserName;
                strEntity = ((UserInfoEntity)Session["usermodel"]).UserOffice;
            }
            else
            {
                Log.WriteDefaultLog("main_01 Page_Load", "Session is null");
                return;
            }
            string strURL = HttpContext.Current.Request.Url.AbsolutePath;
            bool bok = Comm.ifhasright(strUserID, strURL);
            if (!bok)
            {
                Response.Write("你无权访问此页面");
                Response.End();
            }

            BindData();
        }
               
        private void BindData()
        {
            DataSet ds = new DataSet();
            try
            {
                ds = ProductDao.getAllProduct("ALL");

                if (ds != null && ds.Tables.Count > 0)
                {
                    dtgLogList.DataSource = ds.Tables[0];
                    dtgLogList.DataBind();
                }
                else
                {
                    dtgLogList.DataBind();
                }
            }
            catch (Exception ex)
            {
                Log.WriteDefaultLog("operationLogBinddata", ex.ToString());
            }
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            Response.Redirect("ProductAdd.aspx");
        }

        protected void dtgLogList_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            dtgLogList.PageIndex = e.NewPageIndex;
            BindData();
        }

        protected void dtgLogList_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                Label lbprodcode = (Label)e.Row.Cells[0].Controls[1];
                LinkButton lbAction = (LinkButton)e.Row.Cells[10].Controls[1];                
                lbAction.Text = "修改";
                lbAction.Attributes.Add("onclick", "javascript:window.location.href='ProductAdd.aspx?prod_code=" + lbprodcode.Text + "';return false");
            }
        }
    }
}